package com.neusoft.databus.policy.repository.impl;

import java.util.List;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;

import com.neusoft.bizcore.web.jpa.repository.AbstractRepository;
import com.neusoft.bizcore.web.support.Searchable;
import com.neusoft.databus.policy.model.PolicyRefLinkage;
import com.neusoft.databus.policy.model.PolicyRefResource;
import com.neusoft.databus.policy.model.QPolicyRefLinkage;
import com.neusoft.databus.policy.repository.CustomizedPolicyRefLinkageRepository;
import com.querydsl.core.BooleanBuilder;
import com.querydsl.jpa.impl.JPAQuery;

public class CustomizedPolicyRefLinkageRepositoryImpl extends AbstractRepository
        implements CustomizedPolicyRefLinkageRepository {

    @Override
    public Page<PolicyRefLinkage> search(Pageable pageable, Searchable searchable) {
        final QPolicyRefLinkage qPolicyRefLinkage = QPolicyRefLinkage.policyRefLinkage;
        final BooleanBuilder where = new BooleanBuilder();
        where.and(super.containsStr(qPolicyRefLinkage.resourceCode, searchable, "resourceCode"));
        final JPAQuery<PolicyRefLinkage> query = this.query().selectFrom(qPolicyRefLinkage).where(where);
        return super.search(query, pageable);
    }

    @Override
    public List<PolicyRefLinkage> search(Searchable searchable) {
        final QPolicyRefLinkage qPolicyRefLinkage = QPolicyRefLinkage.policyRefLinkage;
        final BooleanBuilder where = new BooleanBuilder();
        where.and(super.containsStr(qPolicyRefLinkage.resourceCode, searchable, "resourceCode"));
        final JPAQuery<PolicyRefLinkage> query = this.query().selectFrom(qPolicyRefLinkage).where(where);
        return query.fetch();
    }

    @Override
    protected Class<?> getModelClass() {
        return PolicyRefResource.class;
    }

}
